package io.github.doc.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.psi.PsiFile;
import io.github.doc.action.language.VisitorFactory;
import io.github.doc.action.language.visitor.Visitor;
import org.jetbrains.annotations.NotNull;

/**
 * <p>Company: 深圳振瀚信息技术有限公司成都分公司 </p>
 * <p>Description: </p>
 *
 * @author ZH.Team
 * @version 1.0.0
 * @email "mailto:ZH.Team@zhxx.com"
 * @date 2025.01.05 16:45
 * @since y.y.y
 */
public abstract class AbstractAction extends AnAction {


    /**
     * Action performed
     *
     * @param e e
     * @since y.y.y
     */
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
        if (file == null) {
            return;
        }
        Visitor visitor = VisitorFactory.getPsiFileVisitor(file);
        if (visitor == null) {
            return;
        }
        this.doActionPerformed(visitor, e);
    }

    /**
     * Do action performed
     *
     * @param visitor visitor
     * @param e       e
     * @since y.y.y
     */
    protected abstract void doActionPerformed(Visitor visitor, AnActionEvent e);
}
